import { create } from 'zustand';

// Initial state
const initialState = {
    image: {
        // video_type: 'text2video',
        version: '7',
        prompts: '',
        ratio: '9:16',
        bRefs: [],
        sRefs: [],
        uRefs: [],
        modelStyle: 0,
        isRaw: 0, //草图模式
        stylize: 0.1,
        particularity: 0,
        diversity: 0,
        speed: 1,
        resolution: 'high',
    },
    video: {
        // video_type: 'image2video',
        version: '7',
        prompts: '',
        firstFrame: '',
        lastFrame: '',
        isLoop: 0,
        onceGenerateNum: 4,
        motionSpeed: 'low',
        modelStyle: 'raw',
        resolution: 1,
    },
    selectedType: 'all', //默认all
    modellist: {
        image: [],
        video: [],
    },
    tasklist: {
        image: [],
        video: [],
    },
};

// Create store
const useFormStore = create((set) => ({
    ...initialState,

    // Update form data for a specific type
    setFormData: (type, data) =>
        set((state) => ({
            [type]: { ...state[type], ...data },
        })),

    // Change the selected video type
    setSelectedType: (type) => set({ selectedType: type }),

    // Update the model list data
    setModelData: (data) => set({ modellist: data }),

    setTask: (type, data) =>
        set((state) => ({
            tasklist: { ...state.tasklist, [type]: data },
        })),
}));

export const setFormData = (type, data) =>
    useFormStore.setState((state) => ({
        [type]: { ...state[type], ...data },
    }));
export const setSelectedType = (type) =>
    useFormStore.setState({ selectedType: type });

export const setTask = (type, data) =>
    useFormStore.setState((state) => ({
        tasklist: { ...state.tasklist, [type]: data },
    }));
export default useFormStore;
